Skip to content

feat(sleep): pre-calculate EPUB cover dimensions for FIT/CROP modes#1

Merged
pablohc merged 1 commit intomasterfrom
dev
Jan 23, 2026
Merged

feat(sleep): pre-calculate EPUB cover dimensions for FIT/CROP modes#1
pablohc merged 1 commit intomasterfrom
dev

Conversation

@pablohc
Copy link
Owner

@pablohc pablohc commented Jan 23, 2026

Summary

  • What is the goal of this PR?
    Implement pre-calculated dimensions for EPUB cover image rendering in sleep screen modes (FIT and CROP) to eliminate runtime scaling artifacts and improve visual clarity.

  • What changes are included?

    1. JpegToBmpConverter::getJpegDimensions() - Extract JPEG dimensions from header
    2. Epub::getCoverBmpPath() - Fix ternary operator precedence bug
    3. Epub::generateCoverBmp() - Pre-calculate exact dimensions per mode:
      • FIT: width=480px, height=(480×jpegHeight)/jpegWidth
      • CROP: height=800px, width=(800×jpegWidth)/jpegHeight
      • Convert JPEG to BMP with calculated dimensions (no runtime scaling)
      • Generate separate cache file per mode to avoid scaling artifacts

Additional Context

  • Visual Improvements:

    • Eliminates "blurry" artifacts from aggressive runtime downsampling
    • Pre-scaled images are sharp and properly proportioned
  • Testing Completed:

    • ✅ Verified with various JPEG aspect ratios (portrait, landscape, square)
    • ✅ Confirmed separate cache files (cover_fit.bmp vs cover_crop.bmp) are created per mode
    • ✅ Validated serial logs show correct calculated dimensions:
      [EBP] Calculated FIT dimensions: 480x720 (original JPEG: 600x900)
      [EBP] Calculated CROP dimensions: 533x800 (original JPEG: 600x900)
      
    • ✅ Validated sleep screen visual clarity improvement (no runtime scaling artifacts)

AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? < PARTIALLY >

  • Used for code analysis and implementation validation
  • Manual code review and testing performed
  • All core algorithm decisions validated against requirements

- Add JpegToBmpConverter::getJpegDimensions() to extract JPEG dimensions
- Fix getCoverBmpPath() ternary operator precedence bug
- Pre-calculate exact dimensions per mode:
  * FIT: width=480px, height=(480*jpegHeight)/jpegWidth
  * CROP: height=800px, width=(800*jpegWidth)/jpegHeight
- Generate separate cache files (cover_fit.bmp vs cover_crop.bmp)
- Eliminates runtime scaling artifacts, improves sleep screen clarity
@pablohc pablohc merged commit c6b6b70 into master Jan 23, 2026
2 checks passed
pablohc pushed a commit that referenced this pull request Feb 12, 2026
Address review comments #1 and crosspoint-reader#7:
- Replace all file-scope global variables (gRenderer, gConfig, gScale,
  gCacheBuffer, etc.) with a PngContext struct passed through pDraw->pUser
- Unify file I/O callbacks to use pFile->fHandle instead of global FsFile*
- Remove the unused FsFile opened at the start of decodeToFramebuffer()
  that was never used for actual decoding (duplicate open)
- Use shared PixelCache from PixelCache.h instead of hand-rolled globals
pablohc pushed a commit that referenced this pull request Feb 14, 2026
Address review comments #1 and crosspoint-reader#7:
- Replace all file-scope global variables (gRenderer, gConfig, gScale,
  gCacheBuffer, etc.) with a PngContext struct passed through pDraw->pUser
- Unify file I/O callbacks to use pFile->fHandle instead of global FsFile*
- Remove the unused FsFile opened at the start of decodeToFramebuffer()
  that was never used for actual decoding (duplicate open)
- Use shared PixelCache from PixelCache.h instead of hand-rolled globals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant